﻿#pragma once

#include "Misc/EngineEditorMacros.h"
#include "Object/Object.h"
#include "Path/Path.h"
#include "EditorPageAreaModel.m.h"


class REditorPageModel;
class REditorPageAreaManagerModel;
class REditorSplitableLayoutLeafNode;

//page area  is  a widget to show pages
RCLASS(ExtraHeader=["Pages/EditorPageModel.h","Widgets/Splitable/EditorSplitableLayoutModel.h"] )
class REditorPageAreaModel : public RObject
{
    ROBJECT

public:
    virtual void FirstTimeInitializeObject() override;

    int64_t GetPageNum() const;
    TSharedObjectPtr<REditorPageModel> GetPage(int64_t Index) const; 

    TSharedObjectPtr<REditorPageAreaManagerModel> GetManager() const;
    TSharedObjectPtr<REditorSplitableLayoutLeafNode> GetLayoutNode() const;
protected:
 
    //area might have pages
    //if it have pages, it will not have sub areas
    RFIELD()
    TVector<TSharedObjectPtr<REditorPageModel>> Pages;
    //the index of the front page
    //if have no page, it will be -1
    RFIELD()
    int64_t FrontPageIndex = -1;

    //对应的布局树上的节点
    RFIELD()
    TSharedObjectPtr<REditorSplitableLayoutLeafNode> LayoutNode;
    


    bool bShowingFindAndReplaceDialog = false;
    bool bShowingReplaceWidget = false;

    friend class REditorPageAreaManagerModel;

public:
    //在区域树中，是不是当前关注的区域
    bool IsFocusedInTree() const;

protected:

    //void FindAreaToFocus();
public:
    TDelegate<void, TSharedObjectPtr<REditorPageModel>> OnPageAdded;
    TDelegate<void,int64_t> OnPageClosed;
    TDelegate<void,int64_t> OnPageReplaced;

    //return the index of the page
    //if not found, return -1
    int64_t FindPage(const CString& PageID) const;

    int64_t GetFrontPageIndex() const;
    TSharedObjectPtr<REditorPageModel> GetFrontPage() const;
    void BringPageFront(int64_t Index);
protected:


//搜索和替换
public:
    void OpenSearchTextDialog();
    void OpenReplaceTextDialog();

    bool IsShowingFindAndReplaceDialog() const;
    void CloseFindAndReplaceDialog();

    bool IsShowingReplaceWidget() const;
    void ToggleReplaceWidget();



};